package flst.ipiweb.common;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;

public class Command {

	private int id;
	private Client client;
	private Delivery delivery;
	private Paiement payment;
	private PromotionalCode promotionalCode;
	private List<CommandLine> commandLineList;
	private Date commandDate;
	private float total;
	private boolean validated;

	public Command() {
		Random r = new Random();
		this.setId(r.nextInt(Integer.MAX_VALUE));
		this.commandLineList = new ArrayList<CommandLine>();
	}

	public Command(int id) {
		super();
		this.setId(id);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public Delivery getDelivery() {
		return delivery;
	}

	public void setDelivery(Delivery delivery) {
		this.delivery = delivery;
	}

	public Paiement getPayment() {
		return payment;
	}

	public void setPayment(Paiement payment) {
		this.payment = payment;
	}

	public PromotionalCode getPromotionalCode() {
		return promotionalCode;
	}

	public void setPromotionalCode(PromotionalCode promotionalCode) {
		this.promotionalCode = promotionalCode;
	}

	public List<CommandLine> getCommandLineList() {
		return commandLineList;
	}

	public void setCommandLineList(List<CommandLine> commandLineList) {
		this.commandLineList = commandLineList;
	}

	public float getCommandPrice() {

		float price = 0;

		if (this.commandLineList != null) {
			for (CommandLine line : this.commandLineList) {
				price += line.getTotalPrice();
			}
		}

		return price;

	}

	public float getBillPrice() {
		float price = this.getCommandPrice();

		price -= this.getPromotionalCode().getBillDiscount(this);

		return price;
	}

	public Date getCommandDate() {
		return commandDate;
	}

	public void setCommandDate(Date commandDate) {
		this.commandDate = commandDate;
	}

	public boolean validateCommand() {
		this.setCommandDate(Calendar.getInstance().getTime());
		return true;
	}

	public float getTotal() {
		return total;
	}

	public void setTotal(float total) {
		this.total = total;
	}

	public boolean isValidated() {
		return validated;
	}

	public void setValidated(boolean validated) {
		this.validated = validated;
	}
}
